<template>
    <div class="page">
      <div class="page-top">
        <!-- 面包屑 -->
        <Hreadcrumb :hreadcrumbAry="hreadcrumbAry" />
      </div>
      <div class="page-content">
        <a-form-model layout="inline" style="margin-bottom: 20px" :form="form">
          <!-- <a-form-model-item label="订单类型">
            <a-select default-value="全部" style="width: 100px" v-model="form.databaseName">
              <a-select-option value="SaleDeliveryUpdateHistory">
                销售出库
              </a-select-option>
              <a-select-option value="SaleBackUpdateHistory">
                销售退货
              </a-select-option>
              <a-select-option value="PurchaseOrderUpdateHistory">
                采购订单
              </a-select-option>
              <a-select-option value="PurchaseBackUpdateHistory">
                采购退货
              </a-select-option>
              <a-select-option value="TransVoucherUpdateHistory">
                调拨单
              </a-select-option>
            </a-select>
          </a-form-model-item> -->
          <a-form-model-item label="订单状态">
            <a-select default-value="全部" style="width: 300px" v-model="form.hasDeal">
              <a-select-option value="-1"> 全部 </a-select-option>
              <a-select-option value="0"> 未处理 </a-select-option>
              <a-select-option value="1"> 处理失败 </a-select-option>
              <a-select-option value="2"> 处理成功 </a-select-option>
              <a-select-option value="3"> 采购入库回写成功 </a-select-option>
              <a-select-option value="4"> 反审核(取消)成功 </a-select-option>
              <a-select-option value="5"> 手动取消成功 </a-select-option>
              <a-select-option value="6">
                已关闭(非京东,自动关闭)
              </a-select-option>
              <a-select-option value="7">
                已关闭(自提单,地址非京东仓库,自动关闭)
              </a-select-option>
            </a-select>
          </a-form-model-item>
          <a-form-model-item label="创建时间">
            <a-range-picker show-time format="YYYY-MM-DD HH:mm:ss" v-model="timeValue" @change="bindTime" />
          </a-form-model-item>
          <a-form-model-item label="飞迩编号">
            <a-input v-model="form.scsOrderNo"></a-input>
          </a-form-model-item>
          <a-form-model-item label="管易发货单号">
            <a-input v-model="form.guanyiDeliveryOrderNo"></a-input>
          </a-form-model-item>
          <a-form-model-item>
            <a-button type="primary" html-type="submit" @click="onSubmit"> 提交 </a-button>
            <a-button style="margin-left: 15px" @click="bindReset">
              重置
            </a-button>
          </a-form-model-item>
        </a-form-model>
        <a-table :columns="columns" :data-source="data" :loading="loading" :pagination="pagination"
          @change="handleTableChange">
          <span slot="hasDeal" slot-scope="record">{{
            record == "0"
            ? "未处理"
            : record == "1"
              ? "处理失败"
              : record == "2"
                ? "处理成功"
                : ""
          }}</span>
          <span slot="ScsHasDeal" slot-scope="record">{{
            record == "0"
            ? "未处理"
            : record == "1"
              ? "处理失败"
              : record == "2"
                ? "处理成功"
                : "关闭"
          }}</span>
          <span slot="options" slot-scope="text, record">
            <a-button type="primary" style="margin-right: 15px"
              :hidden="record.hasDeal != '5' && record.hasDeal != '1' ? true : false"
              @click="changeGYlogList(record, '0')">重传</a-button>
            <a-button type="primary" :hidden="record.hasDeal != '0' ? true : false"
              @click="changeGYlogList(record, '5')">拦截</a-button>
          </span>
        </a-table>
      </div>
    </div>
  </template>
  <script>
  import Hreadcrumb from "@/components/Hreadcrumb";
  import { getOrderListOfGy, changeGYlogList } from "@/request/api";
  export default {
    data() {
      return {
        loading: false,
        hreadcrumbAry: [
          { name: "首页", path: "/", query: {} },
          { name: "日志管理", path: "", query: {} },
          { name: "管易订单日志", path: "/GYlist", query: {} },
        ],
        columns: [
          {
            title: "飞迩单号",
            dataIndex: "scsOrderNo",
            key: "scsOrderNo",
          },
          {
            title: "操作时间",
            dataIndex: "createTime",
            key: "createTime",
            width: 200,
          },
          {
            title: "运行时间",
            dataIndex: "updateTime",
            key: "updateTime",
            width: 200,
          },
          {
            title: "管易发货单号",
            dataIndex: "guanyiDeliveryOrderNo",
            key: "guanyiDeliveryOrderNo",
          },
          {
            title: "状态",
            dataIndex: "hasDeal",
            key: "hasDeal",
            slots: { title: "状态" },
            scopedSlots: { customRender: "hasDeal" },
            width: 160,
          },
          {
            title: "操作人",
            dataIndex: "createBy",
            key: "createBy",
            width: 160,
          },
          {
            title: "操作",
            dataIndex: "options",
            key: "options",
            slots: { title: "操作" },
            scopedSlots: { customRender: "options" },
            width: "100px",
          }
        ],
        pagination: { current: 1, size: 10 },
        data: [],
        form: {
          hasDeal: "-1",
          startTime: "",
          endTime: "",
          scsOrderNo: "",
          guanyiDeliveryOrderNo: "",
          dataSource: ""
        },
        databaseName: '',
        timeValue: undefined,
        centerData: []
      };
    },
    components: {
      Hreadcrumb,
    },
    created() {
        this.getOrderListOfGy(1,10)
    },
    methods: {
      async getOrderListOfGy(p, ps) {
        this.loading = true;
        let { startTime, endTime, hasDeal, guanyiDeliveryOrderNo, scsOrderNo } =
          this.form;
        let params =
          "p=" +
          (p - 1) +
          "&ps=" +
          ps +
          "&scsOrderNo=" +
          scsOrderNo +
          "&guanyiDeliveryOrderNo=" +
          guanyiDeliveryOrderNo +
          "&hasDeal=" +
          hasDeal +
          "&startTime=" +
          startTime +
          "&endTime=" +
          endTime
        let { data } = await getOrderListOfGy(params);
        console.log(data);
        if (data.success) {
          this.loading = false;
          let pagination = { ...this.pagination };
          pagination.total = data.content.total;
          this.pagination = pagination;
          this.data = data.content.records;
        } else {
          this.loading = false;
          this.data = [];
        }
      },
  
      bindTime(date, dateString) {
        console.log(date, dateString);
        this.form.startTime = dateString[0];
        this.form.endTime = dateString[1];
      },
      bindReset() {
        this.form = {
          hasDeal: "-1",
          startTime: "",
          endTime: "",
          scsOrderNo: "",
          guanyiDeliveryOrderNo: "",
        };
        this.timeValue = undefined;
        this.getOrderListOfGy(1, 10);
      },
      onSubmit(e) {
        e.preventDefault();
        console.log(this.form);
        this.getOrderListOfGy(1, 10);
      },
      handleTableChange(pagination) {
        console.log(pagination);
        const pager = { ...this.pagination };
        pager.current = pagination.current;
        this.pagination = pager;
        this.getOrderListOfGy(pager.current, pager.size);
      },
      async changeGYlogList(record, hasDeal) {
        let param =
          "id=" +
          record.id +
          "&hasDeal=" +
          hasDeal +
          "&updateBy=" +
          JSON.parse(localStorage.getItem("userInfo")).userName
        let { data } = await changeGYlogList(param);
        if (data.success) {
          this.getOrderListOfGy(this.pagination.current,10);
          this.$message.success("操作成功");
        } else {
          this.$message.error(data.content);
        }
      },
    },
  };
  </script>
  <style>
  .page-content {
    background-color: #fff;
    padding: 25px;
  }
  </style>